﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Job.Entity;
using Job.Web.Framework;

namespace Job.Web.userControls.Personal
{
    public partial class SearchHunterJob : BaseCtrl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string salary = string.Empty;
                WebCommon.SetDropDownFromDict(ddlYearSalary, salary,
                   Constants.GetDictionaryCode(Constants.DictionaryType.SALARY_LEVEL), true);

                WebCommon.LoadLevelDropDownList(ddlAddrFather, ddlAddrSub, AddressRate,
                    "", "", Constants.DictionaryType.ADDR_CITY);
                WebCommon.LoadLevelDropDownList(ddlIndustryFather, ddlIndustrySub, IndustryRelate,
                   "", "", Constants.DictionaryType.INDUSTRY_CLASS);
            }
        }

        protected void btSearch_Click(object sender, EventArgs e)
        {
            JobHunter searcher = new JobHunter();
            searcher.Name = tbJobName.Text.Trim();
            searcher.Salary = ddlYearSalary.SelectedValue;
            searcher.SearchKey = tbSearchKey.Text.Trim();
            if (ddlAddrSub.SelectedValue != null && ddlAddrSub.SelectedValue.Length > 1)
                searcher.OfficeAddress = ddlAddrSub.SelectedValue;
            else if (ddlAddrFather.SelectedValue != null && ddlAddrFather.SelectedValue.Length > 1)
                searcher.OfficeAddress = ddlAddrFather.SelectedValue;

            if (ddlIndustrySub.SelectedValue != null && ddlIndustrySub.SelectedValue.Length > 1)
                searcher.Industry = ddlIndustrySub.SelectedValue;
            else if (ddlIndustryFather.SelectedValue != null && ddlIndustryFather.SelectedValue.Length > 1)
                searcher.Industry = ddlIndustryFather.SelectedValue;

            String key = "SE_" + DateTime.Now.Ticks.ToString();
            Cache[key] = searcher;

            string url = WebCommon.GetApplicationPath(Request)
                + "Item.aspx?categoryid=" + ((int)Constants.CategoryType.Hunter).ToString()
                + "&subjectid=" + ((int)Constants.SubjectType.HunterPositionList).ToString()
                + "&CK=" + key;
            Response.Write("<script>\n");
            Response.Write("  window.open('" + url + "');\n");
            Response.Write("</script>");
        }
    }
}